package com.qifenqian.turbot.module.ui.setting

import android.content.Context
import android.content.Intent
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseActivity
import com.qifenqian.turbot.config.Constant
import com.qifenqian.turbot.module.contract.AccountContract
import com.qifenqian.turbot.module.presenter.AccountPresenter
import com.qifenqian.turbot.module.ui.loginetc.LoginActivity
import com.qifenqian.turbot.util.ActivityCollector
import com.qifenqian.turbot.util.SpUtils
import kotlinx.android.synthetic.main.activity_setting.*
import org.jetbrains.anko.toast

class SettingActivity : BaseActivity<AccountPresenter, AccountContract.View>(), AccountContract.View {
    companion object {
        fun startThis(context: Context) {
            val intent = Intent(context, SettingActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun bindLayoutId(): Int {
        return R.layout.activity_setting
    }

    override fun bindPresenter(): AccountPresenter? {
        return AccountPresenter(this, this)
    }

    override fun initial() {
        ActivityCollector.addActivity(this, Constant.TAG_ACTIVITY_COLLECTOR_LOGOUT)
        ly_setting_security.setOnClickListener {
            // 2018/12/20 15:07 账户与安全 ----->
            SafetyCenterActivity.startThis(this)
        }
        ly_setting_help.setOnClickListener {
            // 2018/12/20 15:07 帮助与反馈 ----->
            HelpActivity.startThis(this)
        }
        ly_setting_about.setOnClickListener {
            //  2018/12/20 15:07 关于我们 ----->
            AboutActivity.startThis(this)
        }
        btn_setting_logout.setOnClickListener {
            SpUtils.getInstance().clearSp(Constant.SP_ACCOUNT)
            ActivityCollector.finishAll(Constant.TAG_ACTIVITY_COLLECTOR_LOGOUT)
            LoginActivity.startThis(this)
//            finish()
            // TODO: 2018/12/20 15:07 退出账号 ----->
//            mPresenter!!.logout(Constant.userCode)
        }
    }

    override fun logoutResult(isSuccess: Boolean, code: Int, msg: String?) {
        if (isSuccess) {
            SpUtils.getInstance().clearSp(Constant.SP_ACCOUNT)
            LoginActivity.startThis(this)
        }
        toast(msg!!)
    }

    override fun onDestroy() {
        super.onDestroy()
        ActivityCollector.removeActivity(this, Constant.TAG_ACTIVITY_COLLECTOR_LOGOUT)
    }
}
